const devServerPort = 8001;
// const devApiHost = "http://localhost:8100";
const devApiHost = "https://api.bltools.bailian-ai.com";
const prodApiHost = "https://api.bltools.bailian-ai.com";

const resolve = dir => require("path").join(__dirname, dir);

module.exports = {
    publicPath: "/",
    outputDir: "dist",
    lintOnSave: false,
    runtimeCompiler: true,
    chainWebpack: config => {
        config.resolve.alias.set("@", resolve("src")),
            config.resolve.alias.set("@components", resolve("src/components")),
            config.resolve.alias.set("@assets", resolve("src/assets")),
            config.resolve.alias.set("@layout", resolve("src/layout")),
            config.resolve.alias.set("@utils", resolve("src/utils")),
            config.resolve.alias.set("@views", resolve("src/views")),
            config.resolve.alias.set("@config", resolve("src/config"));
    },
    devServer: {
        open: true,
        host: "0.0.0.0",
        port: devServerPort,
        overlay: {
            warnings: false,
            errors: true
        },
        proxy: {
            "/development": {
                target: devApiHost,
                changeOrigin: true,
                ws: true,
                pathRewrite: {
                    "^/development": ""
                }
            },
            "/prod": {
                target: prodApiHost,
                changeOrigin: true,
                ws: true,
                pathRewrite: {
                    "^/prod": ""
                }
            }
        }
    },

    configureWebpack: config => {
        if (process.env.NODE_ENV === "production") {
            config.optimization.minimizer[0].options.terserOptions.compress.warnings = false;
            config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true;
            config.optimization.minimizer[0].options.terserOptions.compress.drop_debugger = true;
            config.optimization.minimizer[0].options.terserOptions.compress.pure_funcs = [
                "console.log"
            ];
        }
    }
};
